package com.inforich.web.controller.screenData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.enums.ReportSourceEnum;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.screenData.domain.ReportHotSpot;
import com.inforich.screenData.service.IReportHotSpotService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 热点分布Controller
 *
 * @author hjm
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/screenData/reportHotSpot")
public class ReportHotSpotController extends BaseController {

  @Autowired
  private IReportHotSpotService reportHotSpotService;

  /**
   * 查询热点分布列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:list')")
  @GetMapping("/list")
  public Page<ReportHotSpot> list(Page<ReportHotSpot> page, ReportHotSpot reportHotSpot) {
    Map<String, Object> map = beanToMap(reportHotSpot);
    reportHotSpotService.pageReportHotSpot(page, map);
    return page;
  }


  /**
   * 导出热点分布列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:export')")
  @Log(title = "热点分布", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ReportHotSpot reportHotSpot) {
    Map<String, Object> map = beanToMap(reportHotSpot);
    List<ReportHotSpot> list = reportHotSpotService.listReportHotSpot(map);
    ExcelUtil<ReportHotSpot> util = new ExcelUtil<ReportHotSpot>(ReportHotSpot.class);
    util.exportExcel(response, list, "热点分布数据");
  }

  /**
   * 获取热点分布详细信息
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(reportHotSpotService.getById(id));
  }

  /**
   * 新增热点分布
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:add')")
  @Log(title = "热点分布", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody ReportHotSpot reportHotSpot) {
    reportHotSpot.setSource(ReportSourceEnum.BACK.getDbData());
    return toAjax(reportHotSpotService.save(reportHotSpot));
  }

  /**
   * 修改热点分布
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:edit')")
  @Log(title = "热点分布", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody ReportHotSpot reportHotSpot) {
    reportHotSpot.setSource(ReportSourceEnum.BACK.getDbData());
    return toAjax(reportHotSpotService.updateById(reportHotSpot));
  }

  /**
   * 删除热点分布
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportHotSpot:remove')")
  @Log(title = "热点分布", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(reportHotSpotService.removeByIds(Arrays.asList(ids)));
  }
}
